/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * 
 * @author yaoyuming
 * 
 * @date 2020-05-06 15:50
 */
package com.yao.fin.baidu;

import cn.hutool.core.util.StrUtil;
import com.yao.common.constant.SysConst;
import com.yao.common.helper.SpringFactory;
import com.yao.common.util.RedisUtils;

/**
 * @author yaoyuming
 * @date 2020/05/06 15:50
 */
public class BaiduRedisUtils {

    private static TokenService tokenService;

    public static String getToken() {

        String token = RedisUtils.get(SysConst.REDIS_BAIDU_TOKEN);

        // token为空，重新获取token
        if (StrUtil.isEmpty(token)) {

            tokenService = SpringFactory.getBean(TokenService.class);

            token = tokenService.getAccessToken(BaiduApiConst.API_KEY, BaiduApiConst.SECRET_KEY);
            setToken(token);
        }

        return token;
    }

    public static void setToken(String token) {
        RedisUtils.set(SysConst.REDIS_BAIDU_TOKEN, token);
    }
}